package com.itheima.day11_TeShu;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

public class XML {
    public static void main(String[] args) throws DocumentException {
        //1、创建解析器对象
        SAXReader saxReader = new SAXReader();
        //2、通过解析器对象创建Document对象
        Document document = saxReader.read(new File("E:\\soft\\workspace\\javaAdvance\\work\\src\\com\\itheima\\day11_TeShu\\books.xml"));
        //3、获取根元素对象
        Element rootElement = document.getRootElement();
        List<Element> element = rootElement.elements();
        for (Element element1 : element) {
            Element nameElement = element1.element("name");
            String name = nameElement.getText();
            Element publishingHouseElement= element1.element("publishingHouse");
            String publishingHouse = publishingHouseElement.getText();
            Element publicationTimeElement = element1.element("publicationTime");
            String publicationTime = publicationTimeElement.getText();
            Element priceElement = element1.element("price");
            String price = priceElement.getText();
            System.out.println(name+"--"+publishingHouse+"--"+publicationTime+"--"+price);
        }

    }
}
